﻿using LibNiconico.NiconicoApi.Internal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace LibNiconico.NiconicoApi.Alert
{
    /// <summary>
    /// ニコニコアラートステータスレスポンス
    /// </summary>
    public class NicoAlertStatusResponse : NicoApiInfoXmlResponseBase<NicoAlertError>
    {

        private NicoAlertStatusResponse(XDocument document)
            : base(document)
        {
            this.AlertStatus = NicoAlertAuthenticatedStatus.Parse(document);
            this.AlertClient = this.Succeed ? new NiconicoAlertClient(new NiconicoAlertConnectionInfo(this.AlertStatus.MessageServer)) : null;
        }

        /// <summary>
        /// アラートステータス
        /// </summary>
        public NicoAlertAuthenticatedStatus AlertStatus
        {
            get;
            private set;
        }

        /// <summary>
        /// アラートクライアント
        /// </summary>
        public INiconicoAlertClient AlertClient
        {
            get;
            private set;
        }

        /// <summary>
        /// エラーコード解析
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        protected override NicoAlertError ParseErrorCode(string code)
        {
            return NicoAlertError.Parse(code);
        }

        internal static NicoAlertStatusResponse Parse(XDocument document)
        {
            return new NicoAlertStatusResponse(document);
        }
    }
}
